import { getMVUrl, getMVInfo, getRelatedVideo } from "../../services/video";
Page({
  data: {
    id: 0,
    mvUrl: "",
    mvInfo: {},
    relatedVideo: [],
    danmuList: [
      {
        text: "test!test!",
        color: "#ff0000",
        time: 3,
      },
      {
        text: "test!test!",
        color: "#ffff00",
        time: 8,
      },
    ],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    // 1.获取id
    const id = options.id;
    this.setData({
      id,
    });
    // 2.请求数据
    this.fetchMVUrl();
    this.fetchMVInfo();
    this.fetchRelatedVideo();
  },
  async fetchMVUrl() {
    const res = await getMVUrl(this.data.id);
    this.setData({
      mvUrl: res.data.url,
    });
  },

  async fetchMVInfo() {
    const res = await getMVInfo(this.data.id);
    this.setData({
      mvInfo: res.data,
    });
  },

  async fetchRelatedVideo() {
    const res = await getRelatedVideo(this.data.id);
    this.setData({
      relatedVideo: res.data,
    });
  },
  recommendInfoTap(event) {
    const item = event.currentTarget.dataset.item.vid;
    // wx.navigateTo({
    //   url: `/pages/detail-video/detail-video?id=${item.id}`,
    // })
  },
  onShareAppMessage() {
    return {
      title: "Time Music",
      path: "/pages/main-music/main-music",
      imageUrl: "",
    };
  },
});
